package com.yutian.web.controller;

import com.yutian.common.annotation.Log;
import com.yutian.common.core.controller.BaseController;
import com.yutian.common.enums.BusinessType;
import com.yutian.selfservice.support.ListService;
import com.yutian.selfservice.support.UrlService;
import com.yutian.selfservice.support.utils.Result;
import com.yutian.web.service.URLServiceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/urlService")
public class URLServiceController extends BaseController {
    public static final String prefix = "/selfservice/urlService/";
    @Autowired
    private URLServiceService urlServiceService;

    @RequestMapping("")
    @RequiresPermissions("system:serviceManager:list")
    public String serviceType() {
        return prefix + "/service1";
    }

    @RequiresPermissions("system:serviceManager:list")
    @PostMapping("/list")
    @ResponseBody
    public Result list(UrlService urlService) {
        return urlServiceService.list(urlService);
    }


    @RequiresPermissions("system:serviceManager:remove")
    @Log(title = "服务类型管理", businessType = BusinessType.DELETE)
    @PostMapping("/remove/{id}")
    @ResponseBody
    public Result remove(@PathVariable("id") Long id) {
        return urlServiceService.delete(id);
    }


    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }


    @RequiresPermissions("system:serviceManager:add")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public Result add(UrlService urlService) {
        return urlServiceService.add(urlService);
    }


    @GetMapping ("/edit/{id}")
    @RequiresPermissions("system:serviceManager:edit")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("service", urlServiceService.selectById(id));
        return prefix + "edit";
    }

    @RequiresPermissions("system:serviceManager:edit")
    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PostMapping("/editSave")
    @ResponseBody
    public Result editSave(UrlService urlService) {
        return urlServiceService.edit(urlService);
    }
}
